package robot.gui;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;
import javax.swing.JPanel;

import robot.utils.Paire;
import sun.java2d.loops.DrawLine;

import SpyGround.Main;


public class Roadmap extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8996088180270921335L;

	private Main main;

	private ArrayList<Paire<String, Long>> list = null;
	Graphics graph;
	
	public Roadmap(Main main, int width, int height) {
		// TODO Auto-generated constructor stub
		this.main = main;
		list = new ArrayList<Paire<String,Long>>();
	
		setPreferredSize(new Dimension(width, height));
	}
	
	public void paint (Graphics g) {
		int sens = 0;
		int x = 100;
		int y = 100;
		
		for (Paire<String, Long> item : list) {
			int x_dest = x;
			int y_dest = y;
			switch (sens) {
			case 0:	// droite
				x_dest += item.getSecond() ;	
				break;
			case 1:// bas
				y_dest += item.getSecond() ;
				break;
			case 2:// gauche
				x_dest -= item.getSecond() ;
				break;

			default:// haut
				y_dest += item.getSecond() ;
				break;
			}
			g.drawLine(x, y, x_dest, y_dest);
			x = x_dest;
			y = y_dest;
			if ("Gauche".compareTo(item.getFirst()) == 0)
				sens = (sens - 1) >= 0 ? sens - 1 : 3;
			else
				sens = (sens + 1) % 4;
		}
		
	}

	public void update(Paire<String, Long> p) {
		list.add(p);
		repaint();
	}

}
